#ifndef MY_BLOB_H
#define MY_BLOB_H

#include "opencv/cv.h"

class MyBlob
{
public:
	MyBlob(int X1, int Depth1, int X2, int Depth2)
	{
		m_Pt1 = new CvPoint();
		*m_Pt1 = cvPoint(X1, Depth1);
		m_Pt2 = new CvPoint();
		*m_Pt2 = cvPoint(X2, Depth2);
	}

	~MyBlob()
	{
		delete m_Pt1;
		delete m_Pt2;
	}

	bool isValid(){ return (m_Pt1->y != 0) & (m_Pt2->y != 0);}

	bool MergeIfCan(MyBlob * BlobToMerge)
	{
		if((abs(m_Pt1->x -  BlobToMerge->m_Pt1->x) <= 5) && (abs(m_Pt1->y -  BlobToMerge->m_Pt1->y) <= 5) && (abs(m_Pt2->x -  BlobToMerge->m_Pt2->x) <= 5) && (abs(m_Pt2->y -  BlobToMerge->m_Pt2->y) <= 5))
		{
			m_Pt1->x = (m_Pt1->x + BlobToMerge->m_Pt1->x) /2;
			m_Pt1->y = (m_Pt1->y + BlobToMerge->m_Pt1->y) /2;
			m_Pt2->x = (m_Pt2->x + BlobToMerge->m_Pt2->x) /2;
			m_Pt2->y = (m_Pt2->y + BlobToMerge->m_Pt2->y) /2;
			return true;
		}
		return false;
	}

	CvPoint *m_Pt1;
	CvPoint *m_Pt2;
};

#endif
